import { mapState } from 'vuex'
import {
  fortmatDate,
  rpxToPx,
  pxToRpx,
} from '@/utils/util'
export const globalMixin = {
  computed: {
    ...mapState({
      kUserInfo: state => state.userInfo,
      kIsUserValid: state => {
        if (state.user.cardInfo && state.user.cardInfo.unionid && state.user.cardInfo.wxcardno) {
          return true;
        }
        return false;
      },
    })
  },
  methods: {
    fortmatDate(p1, p2) {
     return fortmatDate(p1, p2);
    },
    rpxToPx,
    pxToRpx,
    pageFailed(errorInfo) {
      if (!errorInfo) {
        errorInfo = {};
      }
      uni.hideLoading();
      uni.showModal({
        title: errorInfo.title || "提示", //提示的标题,
        content: errorInfo.content || "页面加载败, 请返回重试", //提示的内容,
        showCancel: false,
        confirmText: errorInfo.confirmText || "确定", //确定按钮的文字，默认为取消，最多 4 个字符,
        confirmColor: "#3CC51F", //确定按钮的文字颜色,
        success: errorInfo.confirmAction ||
          function (res) {
            uni.navigateBack({
              delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
            });
          }
      });
    }
  },
}